{include file='common/_meta_layui_256' /}
<body>
<style type="text/css">
</style>
<div class="container">
    <a href="">刷新</a>
    <table id="tableinfo" lay-filter="tablefilter"></table>
    
</div>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
  </div>
</script>
{include file="common/_footer_layui_256"}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
var inst1;
var tree;

layui.use(['table','form'], function(){

    var table = layui.table;
  
    //第一个实例
    table.render({
        elem: '#tableinfo'
        ,toolbar: '#toolbarDemo' 
        ,url: '{:url('TableList/index')}' //数据接口
        ,method: 'post' //开启分页
        ,page: true //开启分页
        ,limit:20
        ,cols: [[ //表头
        {field: 'auth_name', title: '权限名称'}
        ,{field: 'auth_id', title: '权限ID'}
        ,{field: 'table_field', title: '字段'}
        ,{field: 'table_title', title: '字段名称'}
        ,{title:'操作', toolbar: '#barDemo'}
        ]]
    });

  //头工具栏事件
    table.on('toolbar(tablefilter)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event){
            case 'add':
                layer.open({
                    type: 2, 
                    content: '{:url('TableList/add')}',
                    area: ['50%', '50%'],
                    cancel: function(index, layero){ 
                        window.location.reload();
                        layer.close(index)
                      return false; 
                    }    
                    
                }); 
            break;
        
        };
    });
      //监听行工具事件
    table.on('tool(tablefilter)', function(obj){
        var data = obj.data;
        //console.log(obj)
        if(obj.event === 'del'){
            layer.confirm('真的删除行么', function(index){
                $.post('{:url('TableList/del')}',{'id':data.id},function(e){
                    if(e.code == 200){
                        layer.msg('删除了')
                        obj.del();
                        layer.close(index);
                    }
                })  
            });
            return false;
        } else if(obj.event === 'edit'){
            layer.open({
                type: 2, 
                content: '{:url('TableList/edit')}?id='+data.id,
                area: ['50%', '50%']   
            });
        }
    });
});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>